<?php

use think\facade\Route;
use Symfony\Component\Finder\Finder;

Route::rest([
    'index'   => ['GET', '', 'list'],
    'read' => ['GET', '/:id', 'detail'],
    'save' => ['POST', '', 'add'],
    'update' => ['PUT', '/:id', 'edit'],
    'delete' => ['DELETE', '/:id', 'delete'],
]);
Route::get('admin/decorate/designer/getTemplateData', 'admin.decorate.Designer/getTemplateData');
Route::get('admin/decorate/designer/getTemplateList', 'admin.decorate.Designer/getTemplateList');


Route::group('admin', function () {
    // 上传图片到本地，并且不公开
    Route::post('index/localUpload', 'admin.Index/localUpload');

    // 分类选择
    Route::get('category/select', 'admin.Category/select');
    Route::get('category/goodsSelect', 'admin.Category/goodsSelect');

    // 配送选择
    Route::get('dispatch/dispatch/select', 'admin.dispatch.Dispatch/select');

    Route::group(function () {
        Route::get('dashboard/total', 'admin.Dashboard/total');
        Route::get('dashboard/chart', 'admin.Dashboard/chart');
        Route::get('dashboard/ranking', 'admin.Dashboard/ranking');

        // 问题反馈
        Route::resource('feedback', 'admin.feedback');

        // 分类管理
        Route::resource('category', 'admin.Category');

        // 提现列表
        Route::get('withdraw', 'admin.Withdraw/list');
        // 提现列表
        Route::get('withdraw/log/:id', 'admin.Withdraw/log');
        // 处理提现
        Route::post('withdraw/handle/:id', 'admin.Withdraw/handle');

        // 分享记录
        Route::get('share/:id', 'admin.Share/list');

        // 用户优惠券记录
        Route::get('user/coupon/:user_id', 'admin.user.Coupon/list');
        // 优惠券领取记录
        Route::get('user/coupon/couponList/:coupon_id', 'admin.user.Coupon/couponList');

        // 配送方式
        Route::resource('dispatch/dispatch', 'admin.dispatch.Dispatch');
    })->middleware('check_rule', 'admin');

    $finder = new Finder();
    $finder->files()->in(__DIR__ . '/admin')->name('*.php');

    foreach ($finder as $file) {
        require $file->getRealPath();
    }

})->middleware('check_login', 'admin');
